<?php
/**
 * Description:微信菜单相关
 * User: wh
 * Date: 2017-07-25
 * Time: 10:22
 */
namespace app\wxbackend\controller\Wx;
class WxMenu
{
    /**
     * @comment 新建菜单
     * @author wuhao
     */
    public static function setMenu()
    {
        $menu = include_once('/var/www/html/zft/application/wxbackend/controller/Wx/conf/wx_menu.conf.php');
        $menu = json_encode($menu, JSON_UNESCAPED_UNICODE);
        $access_token = WxAccessToken::getAccessToken();
        $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$access_token;
        $res = Curl::callWebServer($url, $menu, 'POST');
        var_dump($res);
    }

    /**
     * @comment 删除菜单
     * @author wuhao
     */
    public static function deleteMenu()
    {
        $access_token = WxAccessToken::getAccessToken();
        $url = 'https://api.weixin.qq.com/cgi-bin/menu/delete?access_token='.$access_token;

        $res = Curl::callWebServer($url, '', 'GET');
        var_dump($res);
    }

    /**
     * @comment 获取菜单
     * @author wuhao
     */
    public static function getMenu()
    {
        $access_token = WxAccessToken::getAccessToken();
        $url = 'https://api.weixin.qq.com/cgi-bin/menu/get?access_token='.$access_token;

        $res = Curl::callWebServer($url, '', 'GET');
        var_dump($res);
    }

    /**
     * @comment 设置租户个性化菜单
     * @author wuhao
     */
    public static function setTenantMenu()
    {
        $menu = include_once('/var/www/html/zft/application/wxbackend/controller/Wx/conf/tenant_menu.conf.php');
        $menu = json_encode($menu, JSON_UNESCAPED_UNICODE);
        $access_token = WxAccessToken::getAccessToken();
        $url = 'https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token='.$access_token;

        $res = Curl::callWebServer($url, $menu, 'POST');
        var_dump($res);
    }

    /**
     * @comment 设置业主个性化菜单
     * @author wuhao
     */
    public static function setOwnerMenu()
    {
        $menu = include_once('/var/www/html/zft/application/wxbackend/controller/Wx/conf/owner_menu.conf.php');
        $menu = json_encode($menu, JSON_UNESCAPED_UNICODE);
        $access_token = WxAccessToken::getAccessToken();
        $url = 'https://api.weixin.qq.com/cgi-bin/menu/addconditional?access_token='.$access_token;

        $res = Curl::callWebServer($url, $menu, 'POST');
        var_dump($res);
    }

    public static function getUserMenu($openid)
    {
        $data = ['user_id' => $openid];
        $data = json_encode($data);
        $access_token = WxAccessToken::getAccessToken();
        $url = 'https://api.weixin.qq.com/cgi-bin/menu/trymatch?access_token='.$access_token;
        $res = Curl::callWebServer($url, $data, 'POST');
        var_dump($res);
    }

    public static function deleteTraditionMenu($menuid)
    {
        $data = ['menuid' => $menuid];
        $data = json_encode($data);
        $access_token = WxAccessToken::getAccessToken();
        $url = 'https://api.weixin.qq.com/cgi-bin/menu/delconditional?access_token='.$access_token;
        $res = Curl::callWebServer($url, $data, 'POST');
        var_dump($res);
    }

}